//
//  ZMBMyselfVC.swift
//  HengYouCai
//
//  Created by apple on 2018/5/9.
//  Copyright © 2018年 lwj. All rights reserved.
//

import UIKit

class ZMBMyselfTableCell: UITableViewCell {
    //配置cell
    override func wl_configurationCell(_ modelTemp: Any?, _ listView: UIScrollView, _ indexPath: IndexPath) {
        if let dataArr = modelTemp as? [[[String]]]{
            
            self.imageView?.image = UIImage(named: dataArr[indexPath.section][1][indexPath.row])
            self.textLabel?.text = dataArr[indexPath.section][0][indexPath.row]
            
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: .value1, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .default
        self.textLabel?.font = Font_WL(14)
        self.textLabel?.textColor = Normal_333Color
        self.detailTextLabel?.textColor =   Normal_ThemeColor//Normal_RedColor
        self.detailTextLabel?.font = Font_WL(14)
        self.accessoryView = UIImageView(image: UIImage(named: "safe_ringht"))
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
}
class ZMBMyselfVC: BaseTableViewController {
    //数据源
    fileprivate var dataArr = [
        
        [["投资记录","交易流水"],
         ["invest","trade"]],
        [["邀请好友"],
         ["invite"]],
        [["返现红包","我的加息券","我的礼品卡"],
         ["reward","my_interest","giftcard"]
        ]
    ]
    
    /// 点击返回按钮 闪现白条问题
    var imageViewBar: UIView?
    
    /// 我的钱包数据
    var myWalletaward:JSON?
    /// 用于下拉的时候 判断 是否正在刷新中
    var noRefreshing = true
    
    //认证 操作
    var authenticationAction: String?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = Normal_458Color
        
        self.setNavigation()
        self.setupTableView()
        
        self.mjReloadata()
        
        authenticationButton.addTarget(self, action: #selector(authentication), for: .touchUpInside)
        
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        // 导航栏透明
        self.navigationController?.navigationBar.setBackgroundImage( UIImage(named: "touming"), for: UIBarMetrics.default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
        self.imageViewBar?.alpha = 0
        // 状态栏 字体白色
        UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
        let isloginView = self.tableView.tableHeaderView?.viewWithTag(500)
        let nologinView = self.tableView.tableHeaderView?.viewWithTag(600)
        
        if isLogin() {
            
            var accountName =  WLFileManager.readUserData(forKey: kUserAccount) as! String
            //            accountName.stringb
            
            accountName.replaceSubrange(Range(NSRange(location: 3, length: accountName.count-7), in: accountName)!, with: "****")
            //            accountName.replaceSubrange(NSRange(location: 3, length: accountName.count-7), with: "****")
            //            accountName = accountName.replacingCharacters(in: NSRange(location: 3, length: accountName.count-7), with: "****")
            //            let accountAttName = NSAttributedString(string: accountName)
            //            accountAttName.
            self.settingBtn.setTitle(accountName, for: .normal)
            isloginView?.isHidden = false
            nologinView?.isHidden = true
            self.loadData()
            
        }else{
            self.settingBtn.setTitle("未登录", for: .normal)
            isloginView?.isHidden = true
            nologinView?.isHidden = false
        }
        if !isLogin() {
            self.present(LOGINVC(), animated: true, completion: {
                let window : UIWindow = ((UIApplication.shared.delegate?.window)!)!
                let tabController : UITabBarController = window.rootViewController as! UITabBarController
                tabController.selectedIndex = 0
            })
            
        }
    }
    override func viewWillDisappear(_ animated: Bool) {
        
        super.viewWillDisappear(animated)
        
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
    }
    
    //点击实名认证
    func authentication() {
        if let action = self.authenticationAction {
            jumpToNextVCWithAction(action: action, currentVC: self)
        }
        
    }
    
    /// 设置导航栏
    func setNavigation() {
        // 下个界面的back文字
        self.navigationItem.title = ""
        // tableview自动下沉问题
        if #available(iOS 11.0, *) {
            
            self.tableView.contentInsetAdjustmentBehavior = .never
        } else {
            self.automaticallyAdjustsScrollViewInsets = false
        }
        self.automaticallyAdjustsScrollViewInsets = false
        self.imageViewBar = self.navigationController?.navigationBar.subviews.first
        
        weak var  weakSelf = self
        
        /// 设置按钮
        
        /// 消息
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: self.settingBtn)
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: self.messageBtn)
        
        let settingVC = UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "SettingViewControllerID")
        settingBtn.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext({ (_) in
            weakSelf?.navigationController?.pushViewController(settingVC, animated: true, withHideBottomBarWhenPush: true, pop: false)
        })
        self.messageBtn.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext({ (value) in
            /// 要每次都创建 防止缓存
            let messageVC = UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "DealMessageVCID")
            weakSelf?.badgeView.hide(animated: false, completion: {
                //
            })
            self.navigationController?.pushViewController(messageVC, animated: true)
        })
    }
    
    /// 配置tableView
    func setupTableView() {
        
        self.tableView.tableHeaderView = self.headerView
        self.tableView.sectionFooterHeight = 0
        self.tableView.sectionHeaderHeight = 7.5
        self.tableView.separatorColor = self.tableView.backgroundColor
        self.tableView.separatorInset = UIEdgeInsetsMake(0, 15, 0, 0)
        self.tableView.register(ZMBMyselfTableCell.self, forCellReuseIdentifier: "cellID")
        
        //顶部拉伸不为白色
        let bgLayer = CALayer()
        bgLayer.backgroundColor = ColorFromRGBHex_WL(0x3d3d3d).cgColor
        bgLayer.frame = CGRect(x: 0, y: -JCWSCREENH, width: JCWSCREENW, height: JCWSCREENH)
        self.tableView.layer.insertSublayer(bgLayer, at: 0)
    }
    /// 刷新钱包数据
    
    func reloadMyWalletaward() {
        
        totalAssetsLabel.text = myWalletaward?["totalAssetsLabel"].stringValue
        totalInterestLable.text = myWalletaward?["totalProfitLabel"].stringValue
        balanceLabel.text = myWalletaward?["balanceLabel"].stringValue
        rechargeButton.setTitle(myWalletaward?["rechargeButtonLabel"].stringValue, for: .normal)
        withdrawButton.setTitle(myWalletaward?["withdrawButtonLabel"].stringValue, for: .normal)
        
        let temp = self.tableView.tableHeaderView?.viewWithTag(500)
        let allAssetsLab = temp?.viewWithTag(1001) as! UILabel
        let totalInterestValue = temp?.viewWithTag(1002) as! UILabel
        let availableAmountValue = temp?.viewWithTag(1005)!.viewWithTag(1003) as! UILabel
        
        
        let eyeBtn = temp?.viewWithTag(1004) as! UIButton
        
        let cell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 2))
        
        if eyeBtn.isSelected {
            allAssetsLab.text = "****"
            totalInterestValue.text = "****"
            availableAmountValue.text = "****"
        }else{
            if (self.myWalletaward != nil) {
                allAssetsLab.text = self.myWalletaward?["allAssets"].stringValue
                totalInterestValue.text = self.myWalletaward?["totalInterest"].stringValue
                availableAmountValue.text = self.myWalletaward?["availableAmount"].stringValue
                if self.myWalletaward!["cashBackSum"].floatValue > 0 {
                    cell?.detailTextLabel?.text = (self.myWalletaward?["cashBackSum"].stringValue)! + "元"
                }else{
                    cell?.detailTextLabel?.text = ""
                }
                
            }else{
                allAssetsLab.text = "0.00"
                totalInterestValue.text = "0.00"
                availableAmountValue.text = "0.00"
                cell?.detailTextLabel?.text = ""
            }
            
        }
    }
    
    func mjReloadata() {
        
        weak var  weakSelf = self
        let header =  LWRefreshGifHeader(refreshingBlock: {
            weakSelf?.loadData()
        });
        header?.stateLabel.textColor = Color.white
        header?.lastUpdatedTimeLabel.textColor = Color.white
        header?.isAutomaticallyChangeAlpha = true
        header?.ignoredScrollViewContentInsetTop = -kJcwStatuBarHeight() - 10
        self.tableView.mj_header = header
        self.tableView.bringSubview(toFront: header!)
        let bgLayer = CAGradientLayer()
        bgLayer.backgroundColor = UIColor.white.cgColor
        bgLayer.frame = CGRect(x: 0, y: -JCWSCREENH, width: JCWSCREENW, height: JCWSCREENH)
        self.tableView.layer.insertSublayer(bgLayer, at: 0)
        
    }
    /// 消息小红点
    lazy var badgeView : AXBadgeView = {
        let temp = AXBadgeView()
        
        temp.backgroundColor = UIColor.white
        temp.style = AXBadgeViewStyle.text
        temp.font = Font_WL(9)
        temp.textColor = Normal_ThemeColor //Normal_RedColor
        
        return temp
    }()
    
    lazy var messageBtn : UIButton = {
        let temp = UIButton(type: UIButtonType.custom)
        temp.setImage(UIImage(named: "inform"), for: .normal)
        temp.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
        
        return temp
    }()
    lazy var settingBtn : UIButton = {
        
        let temp = UIButton(type: UIButtonType.custom)
        temp.setImage(UIImage(named: "set"), for: .normal)
        temp.frame = CGRect(x: 0, y: 0, width: 130, height: 32.5)
        temp.titleLabel?.font = Font_WL(12)
        temp.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: -5)
        temp.imageEdgeInsets = UIEdgeInsets(top: 0, left: -4, bottom: 0, right: 10)
        return temp
    }()
    //实名认证按钮
    lazy var authenticationButton: UIButton = {
        let temp = UIButton(type: UIButtonType.custom)
        temp.backgroundColor = UIColor.white
        //        temp.setTitle("提现", for: .normal)
        temp.contentEdgeInsets = UIEdgeInsetsMake(0,10,0,10)
        temp.imageView?.contentMode = .scaleAspectFit
        return temp
    }()
    
    /// 总资产
    var totalAssetsLabel: UILabel!
    /// 累计收益
    var totalInterestLable: UILabel!
    /// 账户余额
    var balanceLabel: UILabel!
    /// 充值
    var rechargeButton: UIButton!
    /// 提现
    var withdrawButton: UIButton!
    
    //表头
    lazy var headerView: UIView = {
        let temp: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 224+kJcwGetNavHeight()-64))
        temp.backgroundColor = self.view.backgroundColor
        /// 背景 渐变图片
        let bgView = UIImageView()
        //        bgView.image = UIImage(named: "background")
        bgView.backgroundColor = ColorFromRGBHex_WL(0x3d3d3d)
        temp.addSubview(bgView)
        bgView.sd_layout().spaceToSuperView(UIEdgeInsetsMake(0, 0, 0, 0))
        bgView.tag = 700
        
        /// 未登录的headerView
        let temp1: UIView = UIView(frame: CGRect(x: 0, y: 0, width: JCWSCREENW, height: 224+kJcwGetNavHeight()-64))
        temp1.backgroundColor = UIColor.clear
        temp1.tag = 600
        temp1.isUserInteractionEnabled = true
        
        temp.addSubview(temp1)
        let loginBtn = UIButton(type: UIButtonType.custom)
        loginBtn.setTitle("登录/注册", for: .normal)
        loginBtn.layer.cornerRadius = 5
        loginBtn.layer.borderColor = UIColor.white.cgColor
        loginBtn.layer.borderWidth = 1
        temp1.addSubview(loginBtn)
        _ = loginBtn.sd_layout()
            .centerXEqualToView(temp1)?
            .topSpaceToView(temp1,90+kJcwGetNavHeight()-64)?
            .heightIs(75/2)?
            .widthIs(235/2)
        loginBtn.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext { (sender) in
            
            self.present(LOGINVC(), animated: true, completion: nil)
        }
        /// 登录的headerView
        let temp2: UIView = UIView(frame: CGRect(x: 0, y: 0, width: JCWSCREENW, height: 224+kJcwGetNavHeight()-64))
        temp2.backgroundColor = UIColor.clear
        temp2.tag = 500
        temp2.isUserInteractionEnabled = true
        temp.addSubview(temp2)
        
        /// 总资产 文字lab
        let allAssetsTextLab = UILabel()
        self.totalAssetsLabel = allAssetsTextLab
        allAssetsTextLab.text = "总资产(元)"
        allAssetsTextLab.numberOfLines = 1
        allAssetsTextLab.font = Font_WL(12)
        allAssetsTextLab.textColor = UIColor.white
        allAssetsTextLab.textAlignment = .left
        temp2.addSubview(allAssetsTextLab)
        _ = allAssetsTextLab.sd_layout()
            .topSpaceToView(temp2,kJcwGetNavHeight() + 22)?
            .leftSpaceToView(temp2,15)?
            .heightIs(15)?.widthIs(100)
        allAssetsTextLab.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW)
        
        /// 总资产 值
        let allAssetsLab = UILabel()
        allAssetsLab.text = "0.00"
        allAssetsLab.font = BoldFont_WL(22)
        allAssetsLab.textColor = ColorFromRGBHex_WL(0xc1a158)
        allAssetsLab.textAlignment = .left
        allAssetsLab.tag = 1001
        temp2.addSubview(allAssetsLab)
        _ = allAssetsLab.sd_layout()
            .topSpaceToView(allAssetsTextLab,5)?
            .leftEqualToView(allAssetsTextLab)?
            .heightIs(22)
        allAssetsLab.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW)
        
        /// 隐藏打开按钮
        let eyeBtn = UIButton(type: UIButtonType.custom)
        eyeBtn.isSelected = UserDefaults.standard.bool(forKey: "isBiyan")
        eyeBtn.setImage(UIImage(named: "self_zengyan"), for: .normal)
        eyeBtn.setImage(UIImage(named: "self_biyan"), for: .selected)
        eyeBtn.tag = 1004
        temp2.addSubview(eyeBtn)
        _ = eyeBtn.sd_layout()
            .rightSpaceToView(temp2,15)?
            .heightIs(20)?
            .widthIs(20)?
            .centerYEqualToView(allAssetsTextLab)
        
        /// 竖直的白线
        let lineView2 = UIView()
        lineView2.backgroundColor = Normal_CCCColor
        temp2.addSubview(lineView2)
        _ = lineView2.sd_layout()
            .topEqualToView(allAssetsTextLab)?
            .centerXEqualToView(temp2)?
            .heightIs(40)?
            .widthIs(0.5)
        
        
        /// 累计收益
        let totalInterestLab = UILabel()
        self.totalInterestLable = totalInterestLab
        totalInterestLab.textColor = UIColor.white
        totalInterestLab.text = "累计收益(元)"
        totalInterestLab.font = Font_WL(12)
        totalInterestLab.textAlignment = .left
        temp2.addSubview(totalInterestLab)
        _ = totalInterestLab.sd_layout()
            .leftSpaceToView(lineView2,15)?
            .topSpaceToView(temp2,kJcwGetNavHeight() + 22)?
            .heightIs(15)
        totalInterestLab.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW/2)
        
        /// 累计收益 值
        let totalInterestValue = UILabel()
        totalInterestValue.tag = 1002
        totalInterestValue.textColor = ColorFromRGBHex_WL(0xc1a158)
        totalInterestValue.text = "0.00"
        totalInterestValue.font = BoldFont_WL(22)
        totalInterestValue.textAlignment = .left
        temp2.addSubview(totalInterestValue)
        _ = totalInterestValue.sd_layout()
            .leftEqualToView(totalInterestLab)?
            .centerYEqualToView(allAssetsLab)?
            .heightIs(22)
        totalInterestValue.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW/2)
        eyeBtn.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext({ (sender) in
            
            eyeBtn.isSelected = !eyeBtn.isSelected
            
            UserDefaults.standard.set(eyeBtn.isSelected, forKey: "isBiyan")
            self.reloadMyWalletaward()
        })
        /// 底部有透明度的view
        let bottomView = UIView()
        bottomView.tag = 1005
        bottomView.backgroundColor = ColorFromRGBHex_WL(0x464646)
        //        bottomView.alpha = 0.2
        temp2.addSubview(bottomView)
        _ = bottomView.sd_layout()
            .bottomSpaceToView(temp2,0)?
            .rightSpaceToView(temp2,0)?
            .leftSpaceToView(temp2,0)?
            .heightIs(75)
        
        
        /// 账户余额
        let availableAmountLab = UILabel()
        self.balanceLabel = availableAmountLab
        availableAmountLab.textColor = Normal_CCCColor
//        availableAmountLab.text = "账户余额(元)"
        availableAmountLab.font = Font_WL(12)
        availableAmountLab.textAlignment = .left
        availableAmountLab.numberOfLines = 1
        bottomView.addSubview(availableAmountLab)
        _ = availableAmountLab.sd_layout()
            .leftSpaceToView(bottomView,15)?
            .topSpaceToView(bottomView,22)?
            .heightIs(12)
        availableAmountLab.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW/2)
        /// 账户余额 值
        let availableAmountValue = UILabel()
        availableAmountValue.tag = 1003
        availableAmountValue.textColor = UIColor.white
        availableAmountValue.text = "0.00"
        availableAmountValue.font = BoldFont_WL(22)
        availableAmountValue.textAlignment = .left
        bottomView.addSubview(availableAmountValue)
        _ = availableAmountValue.sd_layout()
            .leftEqualToView(availableAmountLab)?
            .topSpaceToView(availableAmountLab,6)?
            .heightIs(22)
        availableAmountValue.setSingleLineAutoResizeWithMaxWidth(JCWSCREENW/2)
        availableAmountValue.setMaxNumberOfLinesToShow(1)
        /// 提现
        let withdrawalBtn = UIButton(type: UIButtonType.custom)
        self.withdrawButton = withdrawalBtn
        withdrawalBtn.backgroundColor = UIColor.white
        withdrawalBtn.setTitleColor(Normal_333Color, for: .normal)
        withdrawalBtn.setTitle("提现", for: .normal)
        withdrawalBtn.layer.cornerRadius = 13.5
        withdrawalBtn.titleLabel?.font = Font_WL(12)
        bottomView.addSubview(withdrawalBtn)
        _ = withdrawalBtn.sd_layout()
            .centerYEqualToView(bottomView)?
            .heightIs(27)?
            .widthIs(70)?
            .rightSpaceToView(bottomView,25)
        
        withdrawalBtn.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext({ (_) in
            
            let pswWord = UserDefaults.standard.string(forKey: kUserPaypassword) ?? ""
            let realname = UserDefaults.standard.string(forKey: kRealnameStatus) ?? ""
            
            // 没有设置交易密码 或者是 没有 实名认证跳三部曲
            if pswWord.count < 1 || realname != "1"{
                
                let investPrepare = InvestPrepareVC()
                
                _ = JCWAccountTrilogyAlertView(headerImageNamed: nil, callBack: {
                    //
                    self.navigationController?.pushViewController(investPrepare, animated: true)
                    
                })
                
            }else{
                
                let withdrawalVC = UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "WithdrawViewControllerID")
                
                self.navigationController?.pushViewController(withdrawalVC, animated: true, withHideBottomBarWhenPush: true, pop: false)
            }
            
            
        })
        /// 充值提现
        let rechargeBtn = UIButton(type: UIButtonType.custom)
        self.rechargeButton = rechargeBtn
        rechargeBtn.setTitleColor(UIColor.white, for: .normal)
        rechargeBtn.setTitle("充值", for: .normal)
        rechargeBtn.backgroundColor = ColorFromRGBHex_WL(0xc1a057)
        rechargeBtn.titleLabel?.font = Font_WL(12)
        rechargeBtn.layer.cornerRadius = 13.5
        bottomView.addSubview(rechargeBtn)
        _ = rechargeBtn.sd_layout()
            .centerYEqualToView(bottomView)?
            .rightSpaceToView(withdrawalBtn,22)?
            .heightIs(27)?
            .widthIs(70)
        //MARK:充值按钮时间
        rechargeBtn.rac_signal(for: UIControlEvents.touchUpInside).subscribeNext({ (_) in
            
            let pswWord = UserDefaults.standard.string(forKey: kUserPaypassword) ?? ""
            let realname = UserDefaults.standard.string(forKey: kRealnameStatus) ?? ""
            
            // 没有设置交易密码 或者是 没有 实名认证跳三部曲
            if pswWord.count < 1 || realname != "1"{
                
                let investPrepare = InvestPrepareVC()
                
                _ = JCWAccountTrilogyAlertView(headerImageNamed: nil, callBack: {
                    //
                    self.navigationController?.pushViewController(investPrepare, animated: true)
                    
                })
                
            }else{
                
                let rechargeVC: RechargeViewController = UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "RechargeViewControllerID") as! RechargeViewController
                rechargeVC.isFromAccount = true
                self.navigationController?.pushViewController(rechargeVC, animated: true, withHideBottomBarWhenPush: true, pop: false)
            }
            
        })
        
        temp.addSubview(self.authenticationButton)
        self.authenticationButton.isHidden = true
        self.authenticationButton.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(bottomView.snp.bottom).offset(5)
            make.height.equalTo(78)
        }
        
        return temp
    }()
    
    
}
extension ZMBMyselfVC{
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArr[section][0].count
    }
    override func numberOfSections(in tableView: UITableView) -> Int {
        return dataArr.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cellID") as! ZMBMyselfTableCell
        cell.wl_configurationCell(self.dataArr, tableView, indexPath)
        
        return cell
    }
    
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView()
        view.backgroundColor = Normal_458Color
        return view
        
    }
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        
        if indexPath.section==0 {
            if indexPath.row==0 {
                
                /// 投资记录
                let investRecord = UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "DepositsHistoryVCID") as! DepositsHistoryVC
                investRecord.titleName = dataArr[indexPath.section][0][0]
                self.navigationController?.pushViewController(investRecord, animated: true, withHideBottomBarWhenPush: true, pop: false)
            }else{
                /// 交易流水
                let dealHistory = DealHistoryVC()
                dealHistory.titleName = dataArr[indexPath.section][0][1]
                self.pushVC(dealHistory)
            }
        }else if indexPath.section==1 {
            /// 邀请好友
            self.pushVC(JCWInviteFirendVC())
        }else{
            
            if indexPath.row==0 {//发现红包
//                self.pushVC(ZYReturnRedbagVC())
                let vc = UIStoryboard(name: "Profile", bundle: nil)
                    .instantiateViewController(withIdentifier: "ZYRedBagVCViewController")
                    as! ZYRedBagVCViewController
                vc.titleName = dataArr[indexPath.section][0][0]
                /// 返现红包
                self.pushVC(vc)
            }else if 1 == indexPath.row{//我的加息券
//                let  CouponViewC = NSClassFromString("CouponViewController") as! UIViewController.Type
//
//                let couponViewC = CouponViewC.init()
//                /// 我的红包
//                self.navigationController?.pushViewController(couponViewC, animated: true, withHideBottomBarWhenPush: true, pop: false)
                //我的加息券
                let couponViewC = CouponViewController.init()
                couponViewC.titleName = dataArr[indexPath.section][0][1]
                self.pushVC(couponViewC)
                
            }else{/// 我的礼品卡
                let investRecord = UIStoryboard(name: "Profile", bundle: nil).instantiateViewController(withIdentifier: "KamiNormalVCID")  as! KamiNormalVC
                investRecord.titleName = dataArr[indexPath.section][0][2]
                self.navigationController?.pushViewController(investRecord, animated: true, withHideBottomBarWhenPush: true, pop: false)
            }
            
        }
        
    }
    
}

extension ZMBMyselfVC {
    
    fileprivate func loadData() {
        // 未读消息
        HYCNetService.accountSysAlertNoRead(onSuccess: { (result) in
            //
            self.noRefreshing = true
            
            self.view.hideHUDLoading(0)
            let  json = JSON(result as Any)
            var noReadMsg = json["smgNoRead"].string
            self.badgeView.text = noReadMsg
            if (noReadMsg?.cGInt)! < 1{
                self.badgeView.hide(animated: false, completion: {
                    //
                })
            }else if (noReadMsg?.cGInt)! > 9 {
                noReadMsg = "···"
                self.badgeView.text = noReadMsg
                self.badgeView.show(in: self.messageBtn, animated: false)
                
            }else{
                
                self.badgeView.show(in: self.messageBtn, animated: false)
                
            }
            
        }) { (code, msg) in
            self.noRefreshing = true
            self.view.showHUDFailTips(msg, hideDelay: kHUDHideDelay)
        }
        // 预加载一下 防止网络原因出现00的情况
        let result = UserDefaults.standard.object(forKey: KWalletaward)
        if result != nil {
            self.myWalletaward = JSON(result ?? "")
            self.reloadMyWalletaward()
        }
        // 钱包数据
        HYCNetService.myWalletShowMyWallet(onSuccess: { (result) in
            self.tableView.mj_header?.endRefreshing()
            self.view.hideHUDLoading(0)
            let resultJson = JSON(result!)
            WLFileManager.saveUserData(result, forKey: KWalletaward)
            self.myWalletaward = resultJson
            
            let bindingShow:Bool = resultJson["bindingShow"].boolValue
            if bindingShow {
                self.headerView.height = 224+kJcwGetNavHeight()-64+80
                self.authenticationButton.isHidden = false
            }else{
                self.headerView.height =  224+kJcwGetNavHeight()-64
                self.authenticationButton.isHidden = true
            }
            self.headerView.layoutIfNeeded()
             self.authenticationAction = resultJson["bindingAction"].stringValue
            
            //实名认证 按钮
            let imageUrl = URL(string: self.myWalletaward?["bindingImageUrl"].stringValue ?? "")
            //            self.authenticationButton.kf.setImage(with: ImageResource(downloadURL: imageUrl!), for: .normal)
            self.authenticationButton.kf_setImage(with: ImageResource(downloadURL: imageUrl!), for: .normal)
            
            // 获取data数据
            let investDetailLabel = resultJson["investDetailLabel"].stringValue
            let tradeDetailLabel = resultJson["tradeDetailLabel"].stringValue
            let shareLabel = resultJson["shareLabel"].stringValue
            let redPacketLabel = resultJson["redPacketLabel"].stringValue
            let couponsLabel = resultJson["couponsLabel"].stringValue
            let CDKeyLabel = resultJson["CDKeyLabel"].stringValue
            
            self.dataArr = [
                [[investDetailLabel,tradeDetailLabel],
                 ["invest","trade"]],
                [[shareLabel],
                 ["invite"]],
                [[redPacketLabel,couponsLabel,CDKeyLabel],
                 ["reward","my_interest","giftcard"]
                ]
            ]
            self.tableView.reloadData()
            self.reloadMyWalletaward()
        }) { (code, errMsg) in
            self.tableView.mj_header?.endRefreshing()
            self.view.showHUDFailTips(errMsg, hideDelay: kHUDHideDelay)
            
        }
    }
    
}
